package com.hy.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.hy.admin.dao.MemberIncomeDetailDao;
import com.hy.admin.helper.response.MemberIncomeDetailResponse;
import com.hy.admin.service.IncomeService;
import com.hy.core.response.ServicesResult;
import org.apache.commons.httpclient.HttpStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IncomeServiceImpl implements IncomeService {

    @Autowired
    private MemberIncomeDetailDao memberIncomeDetailDao;

    @Override
    public ServicesResult<List<MemberIncomeDetailResponse>> incomeDetail(Long memberId, Integer pageNum, Integer pageSize) {
        ServicesResult<List<MemberIncomeDetailResponse>> servicesResult = new ServicesResult<>();

        //校验请求参数
        if (memberId == null || memberId < 0){
            servicesResult.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            servicesResult.setStatusMsg("请求报文有误");
            return servicesResult;
        }

        //设置分页条件，Parameters:pageNum 页码pageSize 每页显示数量count 是否进行count查询
        if(pageNum == null || pageNum <= 0){
            //初始页码为1
            pageNum = 1;
        }
        if(pageSize == null || pageSize <= 0){
            //初始数量为20
            pageSize = 20;
        }
        PageHelper.startPage(pageNum, pageSize);

        List<MemberIncomeDetailResponse> dList = memberIncomeDetailDao.selectByMemberId(memberId);
        servicesResult.setResult(dList);
        return servicesResult;
    }
}
